<template>
    <BasicModal v-bind="$attrs" @register="userRegister" :title="getTitle" width="900px"  @ok="submitAudit">
        <BasicTable @register="registerUserTable" :loading="loading" :pagination="{ pageSize: 15 }" :rowSelection="{ type: 'radio' }">
        </BasicTable>
    </BasicModal>
</template>

<script lang="ts" setup>
import { BasicModal, useModalInner } from '/@/components/Modal';
import { ref ,reactive} from 'vue';
import { useListPage } from '/@/hooks/system/useListPage'
import { getUserList } from './LabItemResultList.api';
import { labUserColumns } from './LabItemResultList.data';
import { BasicTable } from '/@/components/Table';



const loading = ref(false);
const getTitle = ref('人员信息');
const queryParam = reactive<any>({});

const formPerData = reactive<Record<string, any>>({
    oper:"",
});

const emits = defineEmits<{
    (event: "getRatifyResult", uId: String, uName: String): void;
    (event: "getAuditResult", uId: String, uName: String): void;
}>();

const [userRegister, { setModalProps, closeModal }] = useModalInner(async (data) => {
    setModalProps({
        minHeight: 180,
    });
    loading.value = true;
    formPerData.oper = data.oper;
    console.log(formPerData.oper);
});

// 注册table数据
const { tableContext } = useListPage({
    tableProps: {
        api: getUserList,
        columns: labUserColumns,
        canResize: false,
        useSearchForm: false,
        showIndexColumn: true,
        showTableSetting: false,
        showActionColumn: false,
        beforeFetch: (params) => {
            return Object.assign(params, queryParam);
        },
    },
})

const [registerUserTable, { getSelectRows }] = tableContext;


async function submitAudit() {
    const selectedRows = getSelectRows()[0];
    const id = selectedRows['id'];
    const realname = selectedRows['realname'];
    closeModal();
    if(formPerData.oper == "ratify"){
        console.log(formPerData.oper);
        emits('getRatifyResult', id, realname);
    }else{
        console.log(formPerData.oper);
        emits('getAuditResult', id, realname);
    }
   

}


</script>